

//
//  ShowVC.m
//  MTime
//
//  Created by Carl_fang on 15/3/28.
//  Copyright (c) 2015年 Carl_fang. All rights reserved.
//

#import "ShowVC.h"
#import "WillShowVC.h"
#import "TableViewController.h"


@interface ShowVC ()
{
    WillShowVC *_willVC;
}
@end

@implementation ShowVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"正在热映",@"即将上映"]];
    seg.frame = CGRectMake(0, 0, 200, 30);
    
    [seg addTarget:self action:@selector(exchange:) forControlEvents:UIControlEventValueChanged];
    
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] init];
    leftItem.title = @"上海";
    
    self.navigationItem.leftBarButtonItem = leftItem;
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] init];
    rightItem.image = [UIImage imageNamed:@"icon_magnifier@2x.png"];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.navigationItem.titleView = seg;
    
    TableViewController *hotMovieVC = [[TableViewController alloc] init];
    
   // CGFloat tableViewW = self.view.bounds.size.width;
   // CGFloat tableViewH = self.view.bounds.size.height;
   // hotMovieVC.view.bounds = CGRectMake(0, 0, tableViewW, tableViewH);
    
    hotMovieVC.tableView.frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.frame.size.width, self.view.frame.size.height);
    [self addChildViewController:hotMovieVC];
    //[self presentViewController:hotMovieVC animated:YES completion:nil];
    [self.view insertSubview:hotMovieVC.view atIndex:0];
    
    
    
    [leftItem release];
    [rightItem release];
    [seg release];
}




- (void)exchange:(UISegmentedControl *)seg
{
    
    NSInteger segIndex = seg.selectedSegmentIndex;
    switch (segIndex) {
        case 0:
        {
            if (self.view.subviews.count > 1) {
                [self.view.subviews[1] removeFromSuperview];
            }
            
        }
            break;
        case 1:
        {
            if (_willVC == nil) {
                _willVC = [[WillShowVC alloc] initWithStyle:UITableViewStylePlain];
                
            }
            
            _willVC.tableView.frame = CGRectMake(self.view.bounds.origin.x, 64, self.view.frame.size.width, self.view.frame.size.height);
            
            [self.view insertSubview:_willVC.view atIndex:1];
        }
            break;
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
